<!doctype html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="学习笔记," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.0" />






<meta name="description" content="前言 使用git已经有一段时间了，好记性不如烂笔头，这里将常用的命令整理下做个记录。
git常用命令


命令
说明




git init
创建版本库


git add
将文件添加到仓库


git commit
将文件提交到仓库


git status
查看仓库状态,文件是否有修改


git diff
查看修改内容


git clone
从远程仓库克隆项目


git push
提交">
<meta property="og:type" content="article">
<meta property="og:title" content="git学习笔记">
<meta property="og:url" content="http://jieminblog.tk/2017/04/06/git学习笔记/index.html">
<meta property="og:site_name" content="jiemin's Blog">
<meta property="og:description" content="前言 使用git已经有一段时间了，好记性不如烂笔头，这里将常用的命令整理下做个记录。
git常用命令


命令
说明




git init
创建版本库


git add
将文件添加到仓库


git commit
将文件提交到仓库


git status
查看仓库状态,文件是否有修改


git diff
查看修改内容


git clone
从远程仓库克隆项目


git push
提交">
<meta property="og:updated_time" content="2017-04-06T01:09:45.470Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="git学习笔记">
<meta name="twitter:description" content="前言 使用git已经有一段时间了，好记性不如烂笔头，这里将常用的命令整理下做个记录。
git常用命令


命令
说明




git init
创建版本库


git add
将文件添加到仓库


git commit
将文件提交到仓库


git status
查看仓库状态,文件是否有修改


git diff
查看修改内容


git clone
从远程仓库克隆项目


git push
提交">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://jieminblog.tk/2017/04/06/git学习笔记/"/>





  <title> git学习笔记 | jiemin's Blog </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  














  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">jiemin's Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">本来无一物，何处惹尘埃</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="http://jieminblog.tk/2017/04/06/git学习笔记/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="我爱的乌托邦">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/uploads/touxiang.jpeg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="jiemin's Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                git学习笔记
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-04-06T09:06:16+08:00">
                2017-04-06
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h1><p> 使用git已经有一段时间了，好记性不如烂笔头，这里将常用的命令整理下做个记录。</p>
<h1 id="git常用命令"><a href="#git常用命令" class="headerlink" title="git常用命令"></a>git常用命令</h1><table>
<thead>
<tr>
<th style="text-align:center">命令</th>
<th style="text-align:center">说明</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center">git init</td>
<td style="text-align:center">创建版本库</td>
</tr>
<tr>
<td style="text-align:center">git add</td>
<td style="text-align:center">将文件添加到仓库</td>
</tr>
<tr>
<td style="text-align:center">git commit</td>
<td style="text-align:center">将文件提交到仓库</td>
</tr>
<tr>
<td style="text-align:center">git status</td>
<td style="text-align:center">查看仓库状态,文件是否有修改</td>
</tr>
<tr>
<td style="text-align:center">git diff</td>
<td style="text-align:center">查看修改内容</td>
</tr>
<tr>
<td style="text-align:center">git clone</td>
<td style="text-align:center">从远程仓库克隆项目</td>
</tr>
<tr>
<td style="text-align:center">git push</td>
<td style="text-align:center">提交本地代码到远程仓库</td>
</tr>
<tr>
<td style="text-align:center">git pull</td>
<td style="text-align:center">从远程仓库拉取项目到本地</td>
</tr>
<tr>
<td style="text-align:center">git checkout</td>
<td style="text-align:center">切换分支</td>
</tr>
<tr>
<td style="text-align:center">git merge</td>
<td style="text-align:center">合并分支</td>
</tr>
<tr>
<td style="text-align:center">git stash</td>
<td style="text-align:center">备份当前工作区内容</td>
</tr>
</tbody>
</table>
<a id="more"></a>
<h1 id="git实例"><a href="#git实例" class="headerlink" title="git实例"></a>git实例</h1><h2 id="远程test项目有master和develop分支，把他们克隆到本地"><a href="#远程test项目有master和develop分支，把他们克隆到本地" class="headerlink" title="远程test项目有master和develop分支，把他们克隆到本地"></a>远程test项目有master和develop分支，把他们克隆到本地</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">git <span class="built_in">clone</span> ssh://xxx/<span class="built_in">test</span></div><div class="line"><span class="built_in">cd</span> <span class="built_in">test</span></div><div class="line">git checkout -b develop origin/develop</div></pre></td></tr></table></figure>
<h2 id="为一个项目创建一个新的test3分支，并切换到test3分支"><a href="#为一个项目创建一个新的test3分支，并切换到test3分支" class="headerlink" title="为一个项目创建一个新的test3分支，并切换到test3分支"></a>为一个项目创建一个新的test3分支，并切换到test3分支</h2><figure class="highlight stylus"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git checkout -<span class="selector-tag">b</span> test3</div></pre></td></tr></table></figure>
<h2 id="git-stash-的使用"><a href="#git-stash-的使用" class="headerlink" title="git stash 的使用"></a>git stash 的使用</h2><p><strong>git stash 使用场景:</strong> </p>
<p>当前工作区内容已被修改，但是并未完成。这时需要修复前面的分支上面的一个bug，可是并不想提交目前的修改，因为修改没有完成。但是，不提交的话，又没有办法checkout到前面的分支。这时使用git stash可以解决</p>
<p><strong>解决办法：</strong> </p>
<p>首先在修改到一半的分支上使用命令<code>git stash</code>,然后切换到要修改bug的分支，修改完毕后再切回修改到一半的分支上，使用命令<code>git stash pop</code>。</p>
<h1 id="后记"><a href="#后记" class="headerlink" title="后记"></a>后记</h1><p>git在eclipse上有集成的git插件，像add操作，在eclipse中已经集成到commit中了，比较方便。但有些git操作还是用git命令行方便，比如在新电脑上拉取远程分支，eclipse中有好几个步骤需要操作，而命令行中一条命令即可。无论是eclipse插件还是命令行方式，都需要我们熟练掌握git命令。以上的git命令都是比较基础，日常开发中用的比较多的，但对于真正的git来讲只是冰山一角，学习的路还很长！</p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>


    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/学习笔记/" rel="tag"># 学习笔记</a>
          
        </div>
      

      
        
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/03/25/windows2016server部署中普审计软件服务端/" rel="next" title="windows2016server部署中普审计软件服务端">
                <i class="fa fa-chevron-left"></i> windows2016server部署中普审计软件服务端
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/04/13/Mac上搭建jenkins-docker-maven-git自动部署/" rel="prev" title="Mac上搭建jenkins+docker+maven+git自动部署">
                Mac上搭建jenkins+docker+maven+git自动部署 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>

          
          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/uploads/touxiang.jpeg"
               alt="我爱的乌托邦" />
          <p class="site-author-name" itemprop="name">我爱的乌托邦</p>
           
              <p class="site-description motion-element" itemprop="description"></p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/archives">
                <span class="site-state-item-count">17</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">15</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#前言"><span class="nav-number">1.</span> <span class="nav-text">前言</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#git常用命令"><span class="nav-number">2.</span> <span class="nav-text">git常用命令</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#git实例"><span class="nav-number">3.</span> <span class="nav-text">git实例</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#远程test项目有master和develop分支，把他们克隆到本地"><span class="nav-number">3.1.</span> <span class="nav-text">远程test项目有master和develop分支，把他们克隆到本地</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#为一个项目创建一个新的test3分支，并切换到test3分支"><span class="nav-number">3.2.</span> <span class="nav-text">为一个项目创建一个新的test3分支，并切换到test3分支</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#git-stash-的使用"><span class="nav-number">3.3.</span> <span class="nav-text">git stash 的使用</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#后记"><span class="nav-number">4.</span> <span class="nav-text">后记</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">我爱的乌托邦</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Pisces
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    
    
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  




  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.0"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.0"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.0"></script>



  



  




	





  





  





  



  
  

  

  

  

  


  

</body>
</html>
